﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using InhollandAir.App_Code;

namespace InhollandAir
{
    public partial class FlightReservations : Page
    {
        private string Totaal;
        private string flightIDdep = "";
        private string flightIDret = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            Changecolor();

            if (Request.Cookies["PendingFlightSearch"] != null)
            {
                if (Request.Cookies["PendingFlightSearch"].Values["ret"] != null)
                {
                    int dep = int.Parse(Request.Cookies["PendingFlightSearch"].Values["dep"]);
                    int ret = int.Parse(Request.Cookies["PendingFlightSearch"].Values["ret"]);
                    ReturnFlight(dep, ret);
                }
                else
                {
                    int dep = int.Parse(Request.Cookies["PendingFlightSearch"].Values["dep"]);
                    OneWayFlight(dep);
                }
            }
            if (Request.Cookies["CurrentView"] != null)
            {
                var user = new User();
                bool userExists = user.Load(Session.SessionID, (Dictionary<string, User>) Application["ActiveUsers"]);
                if (userExists)
                {
                    txt_V2_Address.Text = user.address;
                    txt_V2_Airmiles.Text = user.airmiles.ToString(CultureInfo.InvariantCulture);
                    txt_V2_City.Text = user.city;
                    txt_V2_Country.Text = user.country;
                    txt_V2_DateOfBirth.Text = user.birthdate;
                    txt_V2_Email.Text = user.email;
                    txt_V2_Firstname.Text = user.firstname;
                    txt_V2_Lastname.Text = user.lastname;
                    txt_V2_Phonenr.Text = user.phonenr;
                    txt_V2_Zipcode.Text = user.zipcode;

                    mv_Booking.ActiveViewIndex = int.Parse(Request.Cookies["CurrentView"].Value);
                    Changecolor();
                }
                var currentView = new HttpCookie("view")
                    {
                        HttpOnly = true,
                        Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                        Name = "CurrentView",
                        Expires = DateTime.Now.AddDays(-1d)
                    };
                Response.AppendCookie(currentView);
            }
        }

        protected void btn_Search_Click(object sender, EventArgs e)
        {
            DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat; //--MM/dd/yyyy
            if (rb_Return.Checked) //Run when radio button return is checked
            {
                int fromIndex = ddl_From.SelectedIndex;
                fromIndex++;
                string from = fromIndex.ToString(CultureInfo.InvariantCulture);

                int toIndex = ddl_To.SelectedIndex;
                toIndex++;
                string to = toIndex.ToString(CultureInfo.InvariantCulture);

                string departureDate = txt_DepartureDate.Text;
                string returnDate = txt_ReturnDate.Text;

                DateTime ddt = DateTime.Parse(departureDate, usDtfi);
                string conDepDate = ddt.ToString("yyyy-MM-dd");

                DateTime rdt = DateTime.Parse(returnDate, usDtfi);
                string conRetDate = rdt.ToString("yyyy-MM-dd");


                if (!string.IsNullOrEmpty(departureDate) && !string.IsNullOrEmpty(returnDate))
                {
                    int dep = 0;
                    int ret = 0;

                    var conn =
                        new SqlConnection(WebConfigurationManager.ConnectionStrings["FlightReservation"].ToString());
                    try
                    {
                        conn.Open();

                        //find departure flight
                        var cmd =
                            new SqlCommand(
                                "SELECT [flightID] FROM [flight] WHERE [departureDate]=@dDate AND [airportID_from]=@From AND [airportID_to]=@To;");
                        cmd.Parameters.AddWithValue("@dDate", conDepDate);
                        cmd.Parameters.AddWithValue("@From", from);
                        cmd.Parameters.AddWithValue("@To", to);
                        cmd.Connection = conn;
                        if (cmd.ExecuteScalar() != null)
                        {
                            string result = cmd.ExecuteScalar().ToString(); //execute scalar to get matching flight ID.
                            dep = int.Parse(result);
                        }
                        else // No flight found
                        {
                            lbl_Info.Text = "No flight found.";
                        }

                        //find return flight
                        var cmd2 =
                            new SqlCommand(
                                "SELECT [flightID] FROM [flight] WHERE [departureDate]=@dDate AND [airportID_from]=@To AND [airportID_to]=@From;");
                        cmd2.Parameters.AddWithValue("@dDate", conRetDate);
                        cmd2.Parameters.AddWithValue("@From", from);
                        cmd2.Parameters.AddWithValue("@To", to);
                        cmd2.Connection = conn;
                        if (cmd2.ExecuteScalar() != null)
                        {
                            string result2 = cmd2.ExecuteScalar().ToString();
                            //execute scalar to get matching flight ID.
                            ret = int.Parse(result2);
                        }
                        else // No flight found
                        {
                            lbl_Info.Text = "No flight found.";
                        }
                        if (dep != 0 && ret != 0)
                        {
                            ReturnFlight(dep, ret);
                        }
                    }
                    catch (SqlException sexc)
                    {
                        lbl_V1_Info.Text = "Database unavailable please try again later.";
                        Logging.WriteError(sexc.Message);
                    }
                    catch (Exception exc)
                    {
                        lbl_V1_Info.Text = "Fatal system error. Please contact customerservice.";
                        Logging.WriteError(exc.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            else //Run when oneway radio button is checked.
            {
                int fromIndex = ddl_From.SelectedIndex;
                fromIndex++;
                string from = fromIndex.ToString(CultureInfo.InvariantCulture);

                int toIndex = ddl_To.SelectedIndex;
                toIndex++;
                string to = toIndex.ToString(CultureInfo.InvariantCulture);

                string departureDate = txt_DepartureDate.Text;

                if (!string.IsNullOrEmpty(departureDate))
                {
                    DateTime dt = DateTime.Parse(departureDate, usDtfi);
                    string conDepDate = dt.ToString("yyyy-MM-dd");

                    var conn =
                        new SqlConnection(WebConfigurationManager.ConnectionStrings["FlightReservation"].ToString());
                    try
                    {
                        conn.Open();
                        var cmd =
                            new SqlCommand(
                                "SELECT [flightID] FROM [flight] WHERE [departureDate]=@dDate AND [airportID_from]=@From AND [airportID_to]=@To;");
                        cmd.Parameters.AddWithValue("@dDate", conDepDate);
                        cmd.Parameters.AddWithValue("@From", from);
                        cmd.Parameters.AddWithValue("@To", to);
                        cmd.Connection = conn;
                        if (cmd.ExecuteScalar() != null)
                        {
                            string result = cmd.ExecuteScalar().ToString(); //execute scalar to get matching flight ID.
                            int dep = int.Parse(result);
                            OneWayFlight(dep);
                        }
                        else // No flight found
                        {
                            lbl_Info.Text = "No flight found.";
                        }
                    }
                    catch (SqlException sexc)
                    {
                        lbl_V1_Info.Text = "Database unavailable please try again later.";
                        Logging.WriteError(sexc.Message);
                    }
                    catch (Exception exc)
                    {
                        lbl_V1_Info.Text = "Fatal system error. Please contact customerservice.";
                        Logging.WriteError(exc.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }

        //Change to oneway flight search.
        protected void rb_OneWay_CheckedChanged(object sender, EventArgs e)
        {
            if (rb_OneWay.Checked)
            {
                txt_ReturnDate.Text = null;
                tbl_V1_FD_Return.Visible = false;
                txt_ReturnDate.Enabled = false;
            }
        }

        //Change to return flight search.
        protected void rb_Return_CheckedChanged(object sender, EventArgs e)
        {
            if (rb_Return.Checked)
            {
                tbl_V1_FD_Return.Visible = true;
                txt_ReturnDate.Enabled = true;
            }
        }

        protected void ReturnFlight(int dep, int ret)
        {
            mv_Booking.ActiveViewIndex = 1;
            Changecolor();
            int flightTotal = 0;

            var pendingFlightSearch = new HttpCookie("Flight")
                {
                    HttpOnly = true,
                    Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                    Expires = DateTime.Now.AddDays(1d),
                    Name = "PendingFlightSearch"
                };
            pendingFlightSearch.Values["dep"] = dep.ToString(CultureInfo.InvariantCulture);
            pendingFlightSearch.Values["ret"] = ret.ToString(CultureInfo.InvariantCulture);
            Response.AppendCookie(pendingFlightSearch);

            var conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["FlightReservation"].ToString());
            try
            {
                conn.Open();
                var cmd =
                    new SqlCommand(
                        "SELECT FL.airmiles, FL.departureDate, A1.country AS fromcountry, A1.city AS fromcity, A2.country AS arivalcountry, A2.city AS arivalcity, TravelTime, IntFlightNum FROM flight as FL INNER JOIN airport A1 ON A1.airportID = FL.airportID_from INNER JOIN airport A2 ON A2.airportID = FL.airportID_to WHERE flightID =@dep;");
                cmd.Parameters.AddWithValue("@dep", dep.ToString(CultureInfo.InvariantCulture));
                cmd.Connection = conn;
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lbl_V1_Dep_Price.Text = dr["airmiles"] + " Inhollandmiles";
                        lbl_V1_Dep_Departure.Text = dr["fromcity"] + ", " + dr["fromcountry"];
                        lbl_V1_Dep_Arival.Text = dr["arivalcity"] + ", " + dr["arivalcountry"];
                        lbl_V1_Dep_TravelTime.Text = dr["TravelTime"] + "Hours";
                        lbl_V1_Dep_IntFlightNumber.Text = dr["IntFlightNum"].ToString();

                        lbl_V3_Dep.Text = dr["fromcity"] + ", " + dr["fromcountry"] + " to " + dr["arivalcity"] + ", " +
                                          dr["arivalcountry"];

                        DateTime dt = DateTime.Parse(dr["departureDate"].ToString());
                        string conDepDate = dt.ToString("yyyy-MM-dd");
                        lbl_V3_Dep_Date.Text = conDepDate;
                        lbl_V3_Dep_Miles.Text = dr["airmiles"].ToString();
                        flightTotal += int.Parse(dr["airmiles"].ToString());
                    }
                }
                else // No flight found
                {
                    mv_Booking.ActiveViewIndex = 0;
                    Changecolor();
                    lbl_Info.Text = "No flight found.";
                }
                dr.Close();

                var cmd2 =
                    new SqlCommand(
                        "SELECT FL.airmiles, FL.departureDate, A1.country AS fromcountry, A1.city AS fromcity, A2.country AS arivalcountry, A2.city AS arivalcity, TravelTime, IntFlightNum FROM flight as FL INNER JOIN airport A1 ON A1.airportID = FL.airportID_from INNER JOIN airport A2 ON A2.airportID = FL.airportID_to WHERE flightID =@ret;");
                cmd2.Parameters.AddWithValue("@ret", ret.ToString(CultureInfo.InvariantCulture));
                cmd2.Connection = conn;
                SqlDataReader dr2 = cmd2.ExecuteReader();
                if (dr2.HasRows)
                {
                    while (dr2.Read())
                    {
                        lbl_V1_Ret_Price.Text = dr2["airmiles"] + " Inhollandmiles";
                        lbl_V1_Ret_Departure.Text = dr2["fromcity"] + ", " + dr2["fromcountry"];
                        lbl_V1_Ret_Arival.Text = dr2["arivalcity"] + ", " + dr2["arivalcountry"];
                        lbl_V1_Ret_TravelTime.Text = dr2["TravelTime"] + "Hours";
                        lbl_V1_Ret_IntFlightNumber.Text = dr2["IntFlightNum"].ToString();

                        lbl_V3_Ret.Text = dr2["fromcity"] + ", " + dr2["fromcountry"] + " to " + dr2["arivalcity"] +
                                          ", " + dr2["arivalcountry"];
                        DateTime dt2 = DateTime.Parse(dr2["departureDate"].ToString());
                        string conDepDate2 = dt2.ToString("yyyy-MM-dd");
                        lbl_V3_Ret_Date.Text = conDepDate2;
                        lbl_V3_Ret_Miles.Text = dr2["airmiles"].ToString();
                        flightTotal += int.Parse(dr2["airmiles"].ToString());
                    }
                }
                else
                {
                    mv_Booking.ActiveViewIndex = 0;
                    Changecolor();
                    lbl_Info.Text = "No flight found.";
                }
                dr2.Close();
            }
            catch (SqlException sexc)
            {
                lbl_V1_Info.Text = "Database unavailable please try again later.";
                Logging.WriteError(sexc.Message);
            }
            catch (Exception exc)
            {
                lbl_V1_Info.Text = "Fatal system error. Please contact customerservice.";
                Logging.WriteError(exc.Message);
            }
            finally
            {
                conn.Close();
            }
            lbl_V3_Total.Text = flightTotal.ToString(CultureInfo.InvariantCulture);
            Totaal = flightTotal.ToString(CultureInfo.InvariantCulture);
            flightIDdep = dep.ToString(CultureInfo.InvariantCulture);
            flightIDret = ret.ToString(CultureInfo.InvariantCulture);
        }

        protected void OneWayFlight(int dep)
        {
            mv_Booking.ActiveViewIndex = 1;
            Changecolor();
            tbl_V1_FD_Return.Visible = false;
            int flightTotal = 0;

            var pendingFlightSearch = new HttpCookie("Flight")
                {
                    HttpOnly = true,
                    Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                    Expires = DateTime.Now.AddDays(1d),
                    Name = "PendingFlightSearch"
                };
            pendingFlightSearch.Values["dep"] = dep.ToString(CultureInfo.InvariantCulture);
            Response.AppendCookie(pendingFlightSearch);


            var conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["FlightReservation"].ToString());
            try
            {
                conn.Open();
                var cmd =
                    new SqlCommand(
                        "SELECT FL.airmiles, FL.departureDate, A1.country AS fromcountry, A1.city AS fromcity, A2.country AS arivalcountry, A2.city AS arivalcity, TravelTime, IntFlightNum FROM flight as FL INNER JOIN airport A1 ON A1.airportID = FL.airportID_from INNER JOIN airport A2 ON A2.airportID = FL.airportID_to WHERE flightID =@dep;");
                cmd.Parameters.AddWithValue("@dep", dep.ToString(CultureInfo.InvariantCulture));
                cmd.Connection = conn;
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lbl_V1_Dep_Price.Text = dr["airmiles"] + " Inhollandmiles";
                        lbl_V1_Dep_Departure.Text = dr["fromcity"] + ", " + dr["fromcountry"];
                        lbl_V1_Dep_Arival.Text = dr["arivalcity"] + ", " + dr["arivalcountry"];
                        lbl_V1_Dep_TravelTime.Text = dr["TravelTime"] + "Hours";
                        lbl_V1_Dep_IntFlightNumber.Text = dr["IntFlightNum"].ToString();

                        lbl_V3_Dep.Text = dr["fromcity"] + ", " + dr["fromcountry"] + " to " + dr["arivalcity"] + ", " +
                                          dr["arivalcountry"];

                        DateTime dt = DateTime.Parse(dr["departureDate"].ToString());
                        string conDepDate = dt.ToString("yyyy-MM-dd");
                        lbl_V3_Dep_Date.Text = conDepDate;
                        lbl_V3_Dep_Miles.Text = dr["airmiles"].ToString();
                        flightTotal = int.Parse(dr["airmiles"].ToString());
                    }
                }
                else // No flight found
                {
                    mv_Booking.ActiveViewIndex = 0;
                    Changecolor();
                    lbl_Info.Text = "No flight found.";
                }
                dr.Close();
                lbl_V1_Dep_Arival.Text = dep.ToString(CultureInfo.InvariantCulture);
            }
            catch (SqlException sexc)
            {
                lbl_V1_Info.Text = "Database unavailable please try again later.";
                Logging.WriteError(sexc.Message);
            }
            catch (Exception exc)
            {
                lbl_V1_Info.Text = "Fatal system error. Please contact customerservice.";
                Logging.WriteError(exc.Message);
            }
            finally
            {
                conn.Close();
            }
            lbl_V3_Total.Text = flightTotal.ToString(CultureInfo.InvariantCulture);
            Totaal = flightTotal.ToString(CultureInfo.InvariantCulture);
            flightIDdep = dep.ToString(CultureInfo.InvariantCulture);
        }


        protected void btn_V1_PreScreen_Click(object sender, EventArgs e)
        {
            var pendingFlightSearch = new HttpCookie("PendingFlightSearch")
                {
                    HttpOnly = true,
                    Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                    Expires = DateTime.Now.AddDays(-1d)
                };
            Response.AppendCookie(pendingFlightSearch);

            --mv_Booking.ActiveViewIndex;
            Changecolor();
        }

        protected void btn_V1_Continue_Click(object sender, EventArgs e)
        {
            var user = new User();
            bool userExists = user.Load(Session.SessionID, (Dictionary<string, User>) Application["ActiveUsers"]);
            if (userExists)
            {
                mv_Booking.ActiveViewIndex = 2;
                Changecolor();

                txt_V2_Address.Text = user.address;
                txt_V2_Airmiles.Text = user.airmiles.ToString(CultureInfo.InvariantCulture);
                txt_V2_City.Text = user.city;
                txt_V2_Country.Text = user.country;
                txt_V2_DateOfBirth.Text = user.birthdate;
                txt_V2_Email.Text = user.email;
                txt_V2_Firstname.Text = user.firstname;
                txt_V2_Lastname.Text = user.lastname;
                txt_V2_Phonenr.Text = user.phonenr;
                txt_V2_Zipcode.Text = user.zipcode;
            }
            else
            {
                mv_Booking.ActiveViewIndex = 2;
                Changecolor();
                Response.Redirect("/Login.aspx");
            }
        }

        protected void lb_V2_UpdateAccount_Click(object sender, EventArgs e)
        {
            var currentView = new HttpCookie("view", "2")
                {
                    HttpOnly = true,
                    Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                    Name = "CurrentView"
                };
            currentView.Expires.AddDays(1d);
            Response.AppendCookie(currentView);
            Response.Redirect("/UpdateAccount.aspx");
        }


        protected void btn_V2_Continue_Click(object sender, EventArgs e)
        {
            mv_Booking.ActiveViewIndex = 3;
            var user = new User();
            bool userExists = user.Load(Session.SessionID, (Dictionary<string, User>) Application["ActiveUsers"]);
            if (userExists)
            {
                lbl_V3_Username.Text = user.username; //Displays username on view 3
                lbl_V3_AbailableBalance.Text = user.airmiles.ToString(CultureInfo.InvariantCulture);
            }
            Changecolor();
        }

        protected void btn_V3_PayNow_Click(object sender, EventArgs e) //PayNow button on view 3
        {
            var user = new User();
            bool userExists = user.Load(Session.SessionID, (Dictionary<string, User>) Application["ActiveUsers"]);
            if (userExists)
            {
                string accountId = user.id.ToString(CultureInfo.InvariantCulture);
                int airmiles = user.airmiles;

                if (airmiles >= int.Parse(Totaal)) //Checks if user has enough airmiles to pay for the flights
                {
                    var conn =
                        new SqlConnection(WebConfigurationManager.ConnectionStrings["FlightReservation"].ToString());
                    try
                    {
                        conn.Open();
                        //adds database record to reservation table for the first flight
                        var cmd =
                            new SqlCommand(
                                "INSERT INTO reservation (reservationTimeDate, accountID, flightID) VALUES (@date, @accountID, @flightID);");
                        cmd.Parameters.AddWithValue("@date", DateTime.Now);
                        cmd.Parameters.AddWithValue("@accountID", accountId);
                        cmd.Parameters.AddWithValue("@flightID", flightIDdep);
                        cmd.Connection = conn;
                        cmd.ExecuteNonQuery();

                        if (flightIDret != "") //checks if the user has a return flight
                        {
                            //adds database record to the reservation table for the return flight
                            var cmd2 =
                                new SqlCommand(
                                    "INSERT INTO reservation (reservationTimeDate, accountID, flightID) VALUES (@date, @accountID, @flightID);");
                            cmd2.Parameters.AddWithValue("@date", DateTime.Now);
                            cmd2.Parameters.AddWithValue("@accountID", accountId);
                            cmd2.Parameters.AddWithValue("@flightID", flightIDret);
                            cmd2.Connection = conn;
                            cmd2.ExecuteNonQuery();
                        }

                        user.airmiles -= int.Parse(Totaal);
                        //appends the user airmiles. by subtracting the ticket total from the user airmiles                           
                        user.Save(); //Saves the user data to the database

                        //removes the search cookie
                        var pendingFlightSearch = new HttpCookie("PendingFlightSearch")
                            {
                                HttpOnly = true,
                                Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                                Expires = DateTime.Now.AddDays(-1d)
                            };
                        Response.AppendCookie(pendingFlightSearch);

                        //refresh the user data
                        var activeUsers = (Dictionary<string, User>) Application["ActiveUsers"];
                        List<string> sessionIds =
                            (from sessionidUser in (Dictionary<string, User>) Application["ActiveUsers"]
                             where sessionidUser.Value.id == user.id
                             select sessionidUser.Key).ToList();
                        foreach (string listItem in sessionIds)
                        {
                            activeUsers[listItem] = user;
                        }
                        Application["ActiveUsers"] = activeUsers;


                        //redirect to bookedflights
                        Response.Redirect("BookedFlights.aspx");
                    }
                    catch (SqlException sexc)
                    {
                        lbl_V1_Info.Text = "Database unavailable please try again later.";
                        Logging.WriteError(sexc.Message);
                    }
                    catch (Exception exc)
                    {
                        lbl_V1_Info.Text = "Fatal system error. Please contact customerservice.";
                        Logging.WriteError(exc.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
                else //when user doesn't have enough airmiles to purchase a ticket
                {
                    lbl_V3_Status.Text = "You don't have enough Inhollandmiles to but this ticket.";
                }
            }
            mv_Booking.ActiveViewIndex = 3;
            Changecolor();
        }

        protected void btn_V3_Cancel_Click(object sender, EventArgs e) //Button Calncel on View 3
        {
            //Remove search cookie and redirect to homepage
            var pendingFlightSearch = new HttpCookie("PendingFlightSearch")
                {
                    HttpOnly = true,
                    Secure = bool.Parse(WebConfigurationManager.AppSettings["sslCookies"]),
                    Expires = DateTime.Now.AddDays(-1d)
                };
            Response.AppendCookie(pendingFlightSearch);

            Response.Redirect("Index.aspx");
        }


        private void Changecolor() //Breadcrumbs color changer (Displays current View)
        {
            if (mv_Booking.ActiveViewIndex == 0)
            {
                lbl_Search.ForeColor = ColorTranslator.FromHtml("#9d426b");
                lbl_FlightDetails.ForeColor = Color.Silver;
                lbl_PassengerInfo.ForeColor = Color.Silver;
                lbl_Payment.ForeColor = Color.Silver;
            }
            if (mv_Booking.ActiveViewIndex == 1)
            {
                lbl_Search.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_FlightDetails.ForeColor = ColorTranslator.FromHtml("#9d426b");
                lbl_PassengerInfo.ForeColor = Color.Silver;
                lbl_Payment.ForeColor = Color.Silver;
            }
            if (mv_Booking.ActiveViewIndex == 2)
            {
                lbl_Search.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_FlightDetails.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_PassengerInfo.ForeColor = ColorTranslator.FromHtml("#9d426b");
                lbl_Payment.ForeColor = Color.Silver;
            }
            if (mv_Booking.ActiveViewIndex == 3)
            {
                lbl_Search.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_FlightDetails.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_PassengerInfo.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_Payment.ForeColor = ColorTranslator.FromHtml("#9d426b");
            }
            if (mv_Booking.ActiveViewIndex == 4)
            {
                lbl_Search.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_FlightDetails.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_PassengerInfo.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
                lbl_Payment.ForeColor = ColorTranslator.FromHtml("#FFCC9966");
            }
        }

        protected void btn_V3_PreScreen_Click(object sender, EventArgs e) //previous screen button on view 3
        {
            mv_Booking.ActiveViewIndex = 2;
            Changecolor();
        }

        protected void btn_V2_PreScreen_Click(object sender, EventArgs e) //previous screen button on view 2
        {
            mv_Booking.ActiveViewIndex = 1;
            Changecolor();
        }
    }
}